﻿/// <reference path="admin-common.js" />   
/// <reference path="../../Common/Scripts/jquery.min.js" />
/// <reference path="~/Content/Common/Widget/kindeditor/kindeditor-min.js" />
(function ($) {
    $.fn.createContent = function (settings) {
        var ie55 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 5.5") != -1);
        var ie6 = (navigator.appName == "Microsoft Internet Explorer" && parseInt(navigator.appVersion) == 4 && navigator.appVersion.indexOf("MSIE 6.0") != -1);
        if ($.browser.msie && (ie55 || ie6)) { }
        var defaultOption = $.extend({}, $.fn.createContent.defaults);
        this.each(function () {
            var $this = $(this);
            var tempsettings = $.data(this, "createContent", { options: $.extend({}, defaultOption, $.fn.createContent.parseOptions(this), settings) });
            var option = tempsettings.options;
            console.log(option);
            $this.click(function () {
                switch ($this, option.type) {
                    case 'tab':
                        createTabs($this, option);
                        break;
                    case 'window':
                        createWindows($this, option);
                        break;
                    default:
                        return;
                }
            });
        });
    };
    $.fn.createContent.defaults = {
        type: '', //创建wekig类型 [tab,windows]
        option: {},
        buildings: [{}],
        tabId: ''
    };
    $.fn.createContent.defaults.building = {
        type: '',
        option: {}
    };
    $.fn.createContent.parseOptions = function (op) {
        return $.extend({}, $.parser.parseOptions(op, {}));
    };
    var createWindows = function (th, option, table) {
        var $this = $(th);
        if ($('#win-' + $this.attr('id')).length == 0)
            $('body').append('<div id=\"win-' + $this.attr('id') + '\"> </div');
        var $win = $('#win-' + $this.attr('id'));
        $win.window(option.option);

    };
    var createTabs = function (th, option) {

        addTab(option.tabId, option.option.title, '', content, true, true);
    };
    var createTable = function (th, option) {

    };
    var createForm = function (th, option) {
    };
    var createCombobox = function (th, option) {

    };
    var createKindeditor = function (th, option) {
    };
    var addTab = function (tabsId, title, url, content, remote, refresh) {
        var tab = null;
        var option = {
            title: title,
            closable: false,
            fit: false,
            height: 'auto'
        };
        if (remote) {
            $.extend(option, { href: url });
        } else {
            $.extend(option, { content: content });
        }
        if ($('#' + tabsId).tabs('exists', title)) {
            $('#' + tabsId).tabs('select', title);
        } else {
            tab = $('#' + tabsId).tabs('add', option);
        }
        return tab;
    };
    var building = function (th, option) {
        $.each(option.building, function () {
            switch (this.type) {
                case 'table':
                    createTable(th, this.option);
                    break;
                case 'form':
                    createForm(th, this.option);
                    break;
                case 'combobox':
                    createCombobox(th, this.option);
                    break;
                case 'kindeditor':
                    createKindeditor(th, this.option);
                    break;
                default:
                    return;
            }
        });
    };
})(jQuery);

var CategoryTypeData = [{ "id": "1010", "text": "学历", "selected": false }, { "id": "1013", "text": "岗位", "selected": false }, { "id": "1015", "text": "产品", "selected": false }, { "id": "1018", "text": "视频", "selected": false }, { "id": "1019", "text": "文章", "selected": false }, { "id": "1020", "text": "性别", "selected": false }, { "id": "1050", "text": "系统语言", "selected": false }, { "id": "1080", "text": "工作类型", "selected": false }, { "id": "1090", "text": "工作经验", "selected": false }, { "id": "2000", "text": "应聘方式", "selected": false }, { "id": "2010", "text": "工作地点", "selected": false }, { "id": "2020", "text": "面试语言", "selected": false }, { "id": "2030", "text": "考核方式", "selected": false }, { "id": "2040", "text": "广告图片", "selected": false}];
var ProductCategoryData;
$(document).ready(function () {
    $('.tabs-menu-a').createContent({ tabId: 'main_tabs' });
});

var LoadCategoryTypeData = function () {

    $.ajax({
        url: '/admin/Category/GetCategoryType',
        dataType: 'json',
        type: 'post',
        async: false,
        success: function (data) {
            CategoryTypeData = data;
        }
    });

};
var LoadProductCategoryData = function () {

    $.ajax({
        url: '/admin/Category/GetProductComboBoxJson',
        dataType: 'json',
        type: 'post',
        async: false,
        success: function (data) {
            ProductCategoryData = data;
        }
    });
};
var FileDelete = function (id) {
    $.ajax({
        type: "POST",
        url: '/admin/Attachment/Delete',
        data: { id: id },
        success: function (msg) {
            AjaxMessage(msg);
        },
        error: function () {
            $.messager.alert('错误', '删除失败！', "error");
        }
    });
};
var DeleteProductImage = function (id) {
    $.ajax({
        type: "POST",
        url: '/admin/Attachment/DeleteProductImage',
        data: { id: id },
        success: function (msg) {

        },
        error: function () {

        }
    });
};
var WindowsDefaultOption = {};
var PanelDefaultOption = {};
var ValidateboxDefaultOption = {};
var DataGridDefaultOption = {};
$.extend();
$.extend();
$.extend();
/*公共函数*/

/*数据表格列*/
var tablecolumn = {
    news: [[
    { field: 'Id', checkbox: true },
    { field: 'MainTitle', title: '标题', align: 'center', width: 150 }, {
        field: 'Culture',
        title: '语言',
        width: 80,
        align: 'center', sortable: true,
        formatter: function (value, rec) {
            for (var i = 0; i < CultureComboboxJsonData.length; i++) {
                if (CultureComboboxJsonData[i].id == value) return CultureComboboxJsonData[i].text;
            }
            return "";

        }
    },
    { field: 'CreateTime', title: '时间', align: 'center', width: 120, formatter: function (value, rec) { return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString(); } },
    {
        field: 'NormalImage',
        title: '图片',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<a name="fancybox-news" class="fancybox-news" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.NormalImage + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/Images/easyicon_cn_32.png" /></a>';
            ;
        }
    },
    {
        field: 'SmallImage',
        title: '图片(小)',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<a name="fancybox-news" class="fancybox-news" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.SmallImage + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/Images/easyicon_cn_32.png" /></a>';
            ;
        }
    },
    {
        field: 'OptEdit',
        title: '修改',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-news-edit" value=' + rowData.Id + '>修改</span>';
            ;
        }
    }
]],
    technologyconsulting: [[
    { field: 'Id', checkbox: true },
    { field: 'MainTitle', title: '标题', align: 'center', width: 150 },
    {
        field: 'Culture',
        title: '语言',
        width: 80,
        align: 'center', sortable: true,
        formatter: function (value, rec) {
            for (var i = 0; i < CultureComboboxJsonData.length; i++) {
                if (CultureComboboxJsonData[i].id == value) return CultureComboboxJsonData[i].text;
            }
            return "";

        }
    },
    { field: 'CreateTime', title: '时间', align: 'center', width: 120, formatter: function (value, rec) { return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString(); } },
    { field: 'OptEdit', title: '修改', width: 40, align: 'center', formatter: function (value, rowData, rec) {
        return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-technologyconsulting-edit" value=' + rowData.Id + '>修改</span>';
        ;
    }
    }
]],
    product: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '名称', width: 150, align: 'center' },
    { field: 'NameEn', title: '名称(EN)', width: 150, align: 'center' },
    { field: 'Model', title: '型号', width: 120, align: 'center' },
    { field: 'Sort', title: '排序', width: 40, align: 'center', sortable: true },
    {
        field: 'CategoryId',
        title: '产品类型',
        width: 80,
        align: 'center', sortable: true,
        formatter: function (value, rec) {
            for (var i = 0; i < ProductCategoryData.length; i++) {
                if (ProductCategoryData[i].id == value) return ProductCategoryData[i].text;
            }
            return "";

        }
    },
    {
        field: 'IsRecommend',
        title: '推荐',
        width: 30,
        align: 'center',
        formatter: function (value, rec) {

            return value ? '是' : '否';
        }
    },
    {
        field: 'NormalImage',
        title: '图片',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<a name="fancybox-product" ref="fancybox-product" class="fancybox-product" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.NormalImage + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/Images/easyicon_cn_32.png" /></a>';
            ;
        }
    },
    {
        field: 'SmallImage',
        title: '图片(小)',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<a name="fancybox-product" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.SmallImage + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/Images/easyicon_cn_32.png" /></a>';
            ;
        }
    },
    {
        field: 'OptEdit',
        title: '修改',
        width: 30,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit-product" name="jqeasyui-datagrid-product-edit" value=' + rowData.Id + '>修改</span>';
            ;
        }
    }
]], link: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '名称', width: 120, align: 'center' },
    { field: 'Sort', title: '排序', align: 'center', width: 30, sortable: true, editor: { type: 'numberbox', options: { precision: 1}} },
    {
        field: 'Image',
        title: '图片',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<a name="fancybox-link" class="fancybox-link" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.Image + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/Images/easyicon_cn_32.png" /></a>';
            ;
        }
    },
    {
        field: 'IsClosed',
        title: '停用',
        width: 80, align: 'center',
        editor: { type: 'checkbox', options: { on: 'true', off: 'false'} },
        formatter: function (value, rec) {

            return value ? '是' : '否';
        }
    },
    {
        field: 'OptEdit',
        title: '修改',
        width: 80,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-link-edit" value=' + rowData.Id + '>修改</span>';
            ;
        }
    }
]], category: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '名称', width: 120, align: 'center' },
    { field: 'NameEn', title: '名称(EN)', width: 120, align: 'center' },
    {
        field: 'Type',
        title: '所属',
        width: 80,
        sortable: true,
        formatter: function (value, rec) {
            for (var i = 0; i < CategoryTypeData.length; i++) {
                if (CategoryTypeData[i].id == value) return CategoryTypeData[i].text;
            }
            return "";

        }
    },
    { field: 'Sort', title: '排序', width: 30, sortable: true, align: 'center' },
    { field: 'CreateTime', align: 'center', title: '时间', width: 120, formatter: function (value, rec) { return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString(); } },
    {
        field: 'OptEdit',
        title: '修改',
        width: 40, align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-category-edit" value=' + rowData.Id + '>修改</span>';
            ;
        }
    }
]], categoryProduct: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '名称', width: 120, align: 'center' },
    { field: 'NameEn', title: '名称(EN)', width: 120, align: 'center' },
    { field: 'Sort', title: '排序', width: 30, sortable: true, align: 'center' },
    { field: 'CreateTime', align: 'center', title: '时间', width: 120, formatter: function (value, rec) { return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString(); } },
    {
        field: 'OptEdit',
        title: '修改',
        width: 40, align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-category-product-edit"  value=' + rowData.Id + '>修改</span>';
        }
    }
]], recruitment: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '职位', width: 120, align: 'center' },
    { field: 'WorkExperience', title: '工作经验', width: 80, align: 'center' },
    { field: 'MonthlySalaryRange', title: '月薪范围', width: 80, align: 'center' },
    { field: 'Sex', title: '性别', width: 80, align: 'center' },
    { field: 'CreateTime', title: '发布日期', align: 'center', width: 120, formatter: function (value, rec) { return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString(); } },
    {
        field: 'OptEdit',
        title: '修改',
        width: 80,
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-recruitment-edit" value=' + rowData.Id + '>修改</span>';
            ;
        }
    }
]], candidates: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '姓名', width: 120, align: 'center' },
    { field: 'Sex', title: '性别', width: 40, align: 'center' },
    {
        field: 'IsRead',
        title: '已阅',
        width: 20, align: 'center', sortable: true,
        formatter: function (value, rec) {
            return value ? '是' : '否';
        }
    },
    { field: 'PostName', title: '岗位', width: 120, align: 'center' },
    { field: 'CreateTime', align: 'center', title: '时间', width: 120, sortable: true, formatter: function (value, rec) { return eval("new " + value.substr(1, value.length - 2)).toLocaleDateString(); } },
    {
        field: 'OptView',
        title: '查看',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-view" name="jqeasyui-datagrid-candidates-view" value=' + rowData.Id + '>查看</span>';
            ;
        }
    }
]], advertisment: [[
    { field: 'Id', checkbox: true },
    { field: 'Name', title: '名称', width: 120, align: 'center' },
    { field: 'Sort', title: '排序', align: 'center', width: 80, sortable: true, editor: { type: 'numberbox', options: { precision: 1}} },
    {
        field: 'Url',
        title: '图片',
        width: 40,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<a name="fancybox-link" style="padding: 0px;margin: 0px;border:0px none;text-align: center;height:16px;width:16px;" href="' + rowData.Url + '"><img style="padding: 0px;margin: 0px;border:0px none;text-align: center;color:#fff;height:16px;width:16px;" alt="' + rowData.Name + '" src="/Content/Admin/image/easyicon_cn_32.png" /></a>';
        }
    },
    {
        field: 'IsClosed',
        title: '停用',
        width: 80,
        editor: { type: 'checkbox', options: { on: 'true', off: 'false'} },
        formatter: function (value, rec) {

            return value ? '是' : '否';
        }
    },
    {
        field: 'OptEdit',
        title: '修改',
        width: 80,
        align: 'center',
        formatter: function (value, rowData, rec) {
            return '<span style="color:red" class="jqeasyui-datagrid-edit" name="jqeasyui-datagrid-advertisment-edit" value=' + rowData.Id + '>修改</span>';
        }
    }
]]
};


